﻿
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using Utils;
using Settings;
namespace PanasonicWarranty.DAL
{
    public partial class DBSysUser
    {
        //// Since this class provides only static methods, make the default constructor private to prevent
        //// instances from being created with "new DBSysUser()"
        private DBSysUser() { }
        
        public static bool Create(string UserName, string Password, string FullName, string Email, string Phone, string Address, int? AgencyID, DateTime? CreatedDate, DateTime? LastModifiedDate, bool Disabled)
		{
            try
            {
                using (SqlConnection conn = new SqlConnection(CommonSetting.ConnectionString))
                {
                    int result = SqlHelper.ExecuteNonQuery(conn, "sp_SysUser_Insert", UserName, Password, FullName, Email, Phone, Address, AgencyID, CreatedDate, LastModifiedDate, Disabled);
                    return (result > 0);
                }
            }catch(Exception ex){
                throw ex;
            }
		}

		public static bool Update(int UserID, string UserName, string Password, string FullName, string Email, string Phone, string Address, int? AgencyID, DateTime? CreatedDate, DateTime? LastModifiedDate, bool Disabled)
		{
            try
            {
                using (SqlConnection conn = new SqlConnection(CommonSetting.ConnectionString))
                {
                    int result = SqlHelper.ExecuteNonQuery(conn, "sp_SysUser_Update", UserID, UserName, Password, FullName, Email, Phone, Address, AgencyID, CreatedDate, LastModifiedDate, Disabled);
                    return (result > 0);
                }
            }catch(Exception ex){
                throw ex;
            }
		}

		public static bool Delete(int UserID)
		{
            try
            {
                using (SqlConnection conn = new SqlConnection(CommonSetting.ConnectionString))
                {
                    int result = SqlHelper.ExecuteNonQuery(conn, "sp_SysUser_Delete", UserID);
                    return (result > 0);
                }
            }catch(Exception ex){
                throw ex;
            }
		}

        public static SqlDataReader GetAll()
        {
            try
            {
                return SqlHelper.ExecuteReader(CommonSetting.ConnectionString, CommandType.StoredProcedure,"sp_SysUser_GetByAll");
            }catch(Exception ex){
                throw ex;
            }
        }

        public static SqlDataReader GetByKey(int UserID)
        {
            try
            {
                return SqlHelper.ExecuteReader(CommonSetting.ConnectionString, "sp_SysUser_GetById", UserID);
            }catch(Exception ex){
                throw ex;
            }
        }

        public static SqlDataReader GetByTop(string top, string where, string order)
        {
            try
            {
                return SqlHelper.ExecuteReader(CommonSetting.ConnectionString, "sp_SysUser_GetByTop", top, where, order);
            }catch(Exception ex){
                throw ex;
            }
        }
	}
}
